HistorialCompra = function(){
		var configWindow = {
			edit: "ctgProductoEditarTop",
			grid: "historialCompraGrid",
			form: "historialCompraForm"
		};
		return {
			guardarsugerencia: function(){
				Asi.message.progress(Asi.constants.SAVING);
					Ext.getCmp("historialCompraForm").getForm().submit({
						url: Asi.constants.CONTEXT_PATH + "/empleado/guardarSugerencia",
		    			timeout: Asi.constants.TIMEOUT_SECONDS,
		    			params: {
		    				"detalleSugerencia": Ext.getCmp("detalleSugerencia").getValue()
		    				
		    			},
		    			success: function(form, action){
		    				Asi.message.alert(action.result.message);
		    				
		    			},
		    			failure: Asi.form.failureProcedure
					});
			},
			init: function(config){
				var historialCompras = config.historialCompras;
				var configToReturn = {};
				configToReturn.items = [];
				configToReturn.menu = AsiBotones.getBotones(AsiGen.getTipoUsuario(), AsiGen.getPantallaId());
				configToReturn.items.push({
					flex: 1,
					title: "HISTORIAL DE COMPRAS",
					autoScroll: true,
					xtype: "panel",
					layout: {
					    type: "vbox",
					    align : "center",
					    pack  : "start"
					},
					defaults: {width: 730, margins: "5 0 5 0"},
					items: [
						{
							xtype: "grid",
							id: "historialCompraGrid",
							height: 150,
							minHeight: 150,
							collapsible : true,
							store: new Ext.data.SimpleStore({
						    	data: historialCompras || [],
						    	fields: [
									"pedidoDetalleNombre",
									"pedidoDetalleTipo",
									"pedidoDetalleCantidad",
									"pedidoDetalleTamanio",
									"pedidoDetalleColor",
									"pedidoDetalleGarantia",
									"pedidoDetalleGarantiaDetalle",
									"pedidoDetalleFecha",
									"pedidoDetalleEntrega",
									"pedidoDetalleEstado",
									"pedidoDireccionEntrega"
				    	        ]
						    }),
						    columns: [
					            {header: "Nombre",  dataIndex: "pedidoDetalleNombre", flex:1, minWidth: 120},
					            {header: "Fecha de Compra",  dataIndex: "pedidoDetalleFecha", flex:1, width: 120},
					            

						    ],

						    listeners: {
						    	selectionchange: function(model, records){
						    		if(!records || records.length <= 0) return;
						    		var record = records[0];
						    		if(record != null){

						    			Asi.form.setValues("historialCompraForm", record.data);
						    			Asi.form.setEnable(Ext.getCmp("historialCompraForm"));
						    		}
						    	},
						    	afterrender: function(){
						    		if(this.store.data.items.length > 0) Asi.grid.selectFirstRow(this);
						    		Asi.form.switchButton(configWindow, "edit");
						    	}
						    }
						},{
				        	xtype: "form",
							id: "historialCompraForm",
							flex: 1,
						    border: false,
						    autoScroll: true,
							layout: {
								type: "table",
								columns: 6,
								style : {
									width : "730px",
									"margin-top" : "5px",
									"margin-bottom" : "40px"
								},
								align : "center"
							},
							defaults: {
								width: 230,
								selectOnFocus: true,
								enforceMaxLength: true,
								maxLength: 200,
								typeAhead: true,
								minChars: 1,
								queryMode: "local",
								forceSelection: true,
								allowEnable: true,
								colspan: 2
							},
							items: [
					        	 {
									xtype: "label",
									text: "DESCRIPCION DE PRODUCTO",
									cls: "x-form-item label_header",
									colspan: 8,
									width: 730
								},
								{xtype: "label", text: "Nombre", cls: "x-form-item label_spacing"},
								{xtype: "label", text: "Tipo", cls: "x-form-item label_spacing"},
								{xtype: "label", text: "Cantidad", cls: "x-form-item label_spacing"},
								{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleNombre",
									maxLength: 100
								},{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleTipo",
									maxLength: 100,
									listeners: {
										change: function(){
											if(Ext.getCmp("historialCompraGrid").getSelectionModel().selected.items[0].data.pedidoDetalleTipo == "1"){
												Ext.getCmp("pedidoDetalleTipo").setValue("CORTINA");
											}else{
											Ext.getCmp("pedidoDetalleTipo").setValue("ALFOMBRA");
											}
										}
									}
								},{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleCantidad",
									maxLength: 100
								},
								{xtype: "label", text: "Tama\u00f1o", cls: "x-form-item label_spacing"},
								{xtype: "label", text: "Color", cls: "x-form-item label_spacing"},
								{xtype: "label", text: "Estado", cls: "x-form-item label_spacing"},
								{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleTamanio",
									maxLength: 100
								},{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleColor",
									maxLength: 100
								},{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleEstado",
									maxLength: 100,
									listeners: {
										change: function(){
											if(Ext.getCmp("historialCompraGrid").getSelectionModel().selected.items[0].data.pedidoDetalleEstado == true){
												Ext.getCmp("pedidoDetalleEstado").setValue("PAGADO");
											} else {
												Ext.getCmp("pedidoDetalleEstado").setValue("COMPRADO/PENDIENTE DE PAGO");
											}
										}
									}
								},
								{xtype: "label", text: "Garantia", cls: "x-form-item label_spacing"},
								{xtype: "label", text: "Fecha de Compra", cls: "x-form-item label_spacing"},
								{xtype: "label", text: "Fecha de Entrega", cls: "x-form-item label_spacing"},
								{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleGarantia",
									maxLength: 100
								},{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleFecha",
									maxLength: 100
								},{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDetalleEntrega",
									maxLength: 100,
									listeners: {
										change: function(){
											if(Ext.getCmp("historialCompraGrid").getSelectionModel().selected.items[0].data.pedidoDetalleEntrega != null){
												var str = Ext.getCmp("historialCompraGrid").getSelectionModel().selected.items[0].data.pedidoDetalleEntrega;
											    var res = str.substring(6, 8) + "/" + str.substring(4, 6) + "/" +   str.substring(0, 4);
												Ext.getCmp("pedidoDetalleEntrega").setValue(res);
											}
										}
									}
								},
								{xtype: "label", text: "Direcci\u00f3n de Entrega", cls: "x-form-item label_spacing", colspan: 6},
								{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "pedidoDireccionEntrega",
									width: 730,
									maxLength: 100,
									colspan: 6
								},
								{xtype: "label", text: "Detalle de la Garant\u00eda", cls: "x-form-item label_spacing", colspan: 6},
								{
									xtype: "textarea",
									fieldCls: "txtborder",
									id: "pedidoDetalleGarantiaDetalle",
									width: 730,
									maxLength: 1000,
									colspan: 6
								},
								
								
								
//								----------------------------------------------------------------------
								{
									xtype: "label",
									text: "SUGERENCIAS",
									cls: "x-form-item label_header",
									colspan: 8,
									width: 730
								},
								{xtype: "label", text: "Escriba su sugerencia", cls: "x-form-item label_spacing",colspan: 8},
								{
									xtype: "textfield",
									fieldCls: "txtborder",
									id: "detalleSugerencia",
									maxLength: 250,
									colspan: 8,
									allowBlank: false,
									width: 730
									
								},

						        {
									xtype: "button",
									colspan: 2,
									iconCls: Asi.constants.icons.SHOPPIN_CAR,
									cls: "background",
									tooltip: "Clic para Enviar Tu Sugerencia",
									text: "Enviar Sugerencia",
									handler : HistorialCompra.guardarsugerencia
									
								}
						
								
								

							]
				        }
				        
				        
					]
					
				});
				return configToReturn;
			}
		};
	}();